<?php
declare (strict_types=1);

namespace app\organization\controller\system;

use app\common\controller\Frontend;
use app\common\enums\AcceptAccountTypeEnum;
use app\common\model\banxi\sys\SysNotification as SysNotificationModel;
use think\db\exception\DbException;
use think\exception\ValidateException;

class SysNotification extends Frontend
{
    protected array $noNeedLogin = [];
    protected array $noNeedPermission = [];

    public function initialize(): void
    {
        parent::initialize();
        $this->model = new SysNotificationModel();
    }


    /**
     * 查询-通知详情
     * @return void
     * @throws DbException
     */
    public function getNotificationInfo(): void
    {
        $param = $this->request->param(['id']);
        try {
            $organizationId = $this->auth->organizationId;
            $this->model->markRead($param['id'], $organizationId, AcceptAccountTypeEnum::ORGAN);
            $info = $this->model->where(['id' => $param['id']])->find();
        } catch (ValidateException $e) {
            $this->fail($e->getError());
        }
        $this->ok('操作成功', removeNull($info));
    }

    /**
     * 分页-通知公告
     * @return void
     * @throws DbException
     */
    public function listMyNotification(): void
    {
        $param = $this->request->param(['index', 'limit', 'searchText']);
        //获取分页数据
        $pageParams = get_page_params($param);
        $organizationId = $this->auth->organizationId;
        $list = $this->model->listMyInfoPage($pageParams['page'], $pageParams['limit'], $organizationId, AcceptAccountTypeEnum::ORGAN, $param['searchText']);
        $this->ok('操作成功', result_row($list));
    }

}
